package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }



    @Override
    public void createBed(BedDto bedDto) {

        //json格式进行转化
        Bed bed = BeanUtil.copyProperties(bedDto, Bed.class);
        // Bed bed = BeanUtil.toBean(bedDto, Bed.class);
        // 设置创建时间
        bed.setCreateTime(LocalDateTime.now());
        //设置创建人
        bed.setCreateBy(2L);
        //设置创建状态
        bed.setBedStatus(1);

        bedMapper.createBed(bed);
    }

    @Override
    public BedVo bedByid(Long id) {
        return BeanUtil.toBean(bedMapper.bedByid(id), BedVo.class);
    }

    @Override
    public void updeteBed(BedDto bedDto) {
        BedVo bedVo = bedByid(bedDto.getId());
        bedVo.setSort(bedDto.getSort());

        bedVo.setBedNumber(bedDto.getBedNumber());
        Bed bed = BeanUtil.toBean(bedVo, Bed.class);
        bed.setUpdateTime(LocalDateTime.now());
        bed.setUpdateBy(1L);
        bedMapper.updateBed(bed);

    }

    @Override
    public void deleteBed(Long id) {
        bedMapper.deleteBed(id);
    }


}

